<template>
	<view class="content">
		<!-- {{lng}} |||
		{{lat}} -->
		<view class="list">
			<view class="list-item" v-for="v in list">
				<image :src="$func.showImg(v.img)"></image>
				<view>
					<view class="item-title">
						{{v.name}}
						<text>{{v.gap_km}}km</text>
					</view>
					<view class="item-address">
						<!-- 店铺地址：哈尔滨市松北区松浦大道观 江国际A区4号楼1单元102室 -->
						店铺地址：{{v.address}}
					</view>

					<view class="sel" @click="selThis(v)">选这个</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import Location from '@/utils/location.js'
	export default {
		data() {
			return {
				good_id: 0,

				list: [],
				page: 1,
				totalPage: 1,

				lng: '',
				lat: ''
			}
		},
		mounted() {
			// uni.getLocation({
			// 	type: 'wgs84', // 返回可以用于uni.openLocation的经纬度，默认为wgs84的gps坐标
			// 	success: (res) => {
			// 		this.location.latitude = res.latitude;
			// 		this.location.longitude = res.longitude;
			// 		console.log('纬度：' + this.location.latitude + '，经度：' + this.location.longitude);
			// 	},
			// 	fail: () => {
			// 		uni.showToast({
			// 			title: '获取位置失败',
			// 			icon: 'none'
			// 		});
			// 	}
			// });
			// console.log('==2=2=2=2=2=')
			// this.getLocation()
		},
		onLoad(options) {
			if(options.lists){
				console.log('-=-=-=options',JSON.parse(options.lists))
				// this.good_id = options.shop_id
				this.good_id = JSON.parse(options.lists)[0].products.map(v => v.id)
				console.log('-=-=goods_id', this.good_id)
			}
			this.getLocation()
			// this.init()
		},
		methods: {
			async getLocation() {
				const url = location.href.split('#')[0];
				Location.getJsApiConfig(url, res => {
					this.lng = res.longitude
					this.lat = res.latitude

					this.getList()
				})
				// .then(res=>{
				// 	alert(res.longitude)
				// 	alert(res.latitude)
				// })
				// .then(res => {
				// 	alert(JSON.stringify(res))
				// 	console.log('-=-=-=-=1')
				// }).catch(err => {
				// 	console.log('-=-=-=err')
				// })
			},
			init() {
				this.page = 1
				this.getList()
			},
			getList() {
				// if (this.page > this.totalPage) return
				uni.request({
					url: '/wanlshop/product/spotList',
					data: {
						good_id: this.good_id,
						page: this.page,
						pointLat: this.lat,
						pointLng: this.lng
					},
					success: res => {
						console.log('--==--=res', res)
						this.list = res.data
						console.log('-==list', this.list)

						// let list = res.data.data
						// if (this.page > 1) {
						// 	list = this.list.concat(list)
						// }
						// this.list = list

						// this.page++
						// this.totalPage = res.data.last_page || 1
					},
					complete() {
						uni.stopPullDownRefresh()
					}
				})
			},

			selThis(item) {
				console.log('-==-item', item)
				this.$func.setPrevPage('addressData', {
					address: item.address,
					name: item.name,
					mobile: item.phone,
					province: '',
					city: '',
					district: '',
					id: item.id
				})
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="less" scoped>
	.content {
		padding: 25rpx;
		background-color: #f4f4f4;

		.list {
			display: flex;
			flex-direction: column;
			gap: 20rpx;

			.list-item {
				display: flex;
				gap: 23rpx;
				background-color: #fff;
				border-radius: 20rpx;
				padding: 25rpx 17rpx;
				position: relative;

				image {
					width: 200rpx;
					height: 200rpx;
					border-radius: 10rpx;
				}

				>view {
					display: flex;
					flex-direction: column;
					gap: 10rpx;
					flex: 1;
				}

				.item-title {
					font-weight: 400;
					font-size: 30rpx;
					color: #333333;
					line-height: 42rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;

					text {
						font-weight: 400;
						font-size: 24rpx;
						color: #888888;
						line-height: 36rpx;
					}
				}

				.item-address {
					font-weight: 400;
					font-size: 24rpx;
					color: #666666;
					line-height: 36rpx;
				}

				.sel {
					width: 150rpx;
					height: 62rpx;
					line-height: 62rpx;
					text-align: center;
					border-radius: 31rpx;
					background-color: #000;
					border-radius: 100rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					font-size: 26rpx;
					color: #FFFFFF;
					position: absolute;
					bottom: 27rpx;
					right: 18rpx;
				}
			}
		}
	}
</style>
